package cn.tedu.utils;/**
 * @Author 金帮嘉诚 @Date 2021-07-15 星期四 19:52
 */
/*本类用于测试*/

import cn.tedu.pojo.Car;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

/**
 * 知识点
 *
 */
public class CarTb {
    /*id int primary key auto_increment,
    name varchar(40) ,
    type varchar(40),
    color varchar(40),
    price DOUBLE(20,2)*/
    public static String insert(Car car) {
        Connection conn = null;
        PreparedStatement ps = null;
        ResultSet rs = null;

        try {
            conn = Jdbc.getCon();
            String sql = "insert into spb_car values(null,?,?,?,?)";
            ps=conn.prepareStatement(sql);
            ps.setString(1, car.getName());
            ps.setString(2, car.getType());
            ps.setString(3, car.getColor());
            ps.setDouble(4, car.getPrice());

            if (ps.executeUpdate() == 0) {
                return "插入失败！数据不正确";
            }
            return "插入成功！";
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
            return "插入失败，类名错误！";
        } catch (SQLException throwables) {
            throwables.printStackTrace();
            return "插入失败，SQL语句错误！";
        } finally {
            Jdbc.closeRPC(rs, ps, conn);
        }

    }
}
